from flask import Flask
# from .views import blue
from .exts import init_exts
import os
from .urls import *

# 如果将templates和static挪出去, 我们还得改路径, 这时候怎么办?
# 拿到根目录
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
print(BASE_DIR)

def create_app():
    # 配置静态文件和模板文件目录
    static_folder = os.path.join(BASE_DIR, 'static')
    template_folder = os.path.join(BASE_DIR, 'templates')
    app = Flask(__name__, static_folder=static_folder, template_folder=template_folder)
    # 注册蓝图
    # app.register_blueprint(blueprint=blue)

    # 配置数据库
    # db_url = 'sqlite:///sqlite3.db'
    db_url = 'mysql+pymysql://root:lzr123456@localhost:3306/flaskdb'
    app.config['SQLALCHEMY_DATABASE_URI'] = db_url
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False # 禁止对象追踪修改
    # 初始化插件
    init_exts(app)
    return app